<template>
    <div class="body">
        <!-- 頭部 -->
        <div class="cards" style="margin-top:10px;">
            <div class="g-card" style="width:100%;">
                <div class="title">平台概览</div>
                <div class="logos-c">
                    <!-- 单位总数 -->
                    <div class="cpt">
                        <div class="img-body">
                            <div class="img-c">
                                <img src="@/assets/images/disktop/logo1.png" />
                            </div>
                        </div>
                        <router-link to="/Management">
                            <div class="t">
                                <h3>{{ firmCount }}</h3>
                                <p>单位总数</p>
                            </div>
                        </router-link>
                    </div>
                    <div class="margin-box"></div>
                    <!-- 资产总数 -->
                    <div class="cpt">
                        <div class="img-body">
                            <div class="img-c">
                                <img src="@/assets/images/disktop/logo2.png" />
                            </div>
                        </div>
                        <div class="t">
                            <h3>{{ assetCount }}</h3>
                            <p>资产总数</p>
                        </div>
                    </div>
                    <div class="margin-box"></div>
                    <!-- 漏洞总数 -->
                    <div class="cpt">
                        <div class="img-body">
                            <div class="img-c"><img src="@/assets/images/disktop/logo3.png" /></div>
                        </div>
                        <router-link to="/bugMgmt">
                            <div class="t">
                                <h3>{{ bugCount }}</h3>
                                <p>漏洞总数</p>
                            </div>
                        </router-link>
                    </div>
                    <div class="margin-box"></div>
                    <!-- 通报总数 -->
                    <div class="cpt">
                        <div class="img-body">
                            <div class="img-c"><img src="@/assets/images/disktop/logo5.png" /></div>
                        </div>
                        <router-link to="/tongbao">
                            <div class="t">
                                <h3>{{ reportCount }}</h3>
                                <p>通报总数</p>
                            </div>
                        </router-link>
                    </div>
                </div>
                <!-- <div class="logos-c" style="margin-top:16px;">
                    <div class="cpt">
                        <div class="img-body">
                            <div class="img-c"><img src="@/assets/images/disktop/logo4.png" /></div>
                        </div>
						<div class="t">
							<h3>{{ inspectCount }}</h3>
							<p>检验总数</p>
						</div>
                    </div>
                    <div class="margin-box"></div>
                </div> -->
            </div>
        </div>
        <div class="cards">
            <div class="g-card" style="margin-right:15px;">
                <div class="title">高危单位排名 TOP 10</div>
                <Grid :gridDatas="grid01" v-on:getTeg="toDetail"></Grid>
            </div>
            <div class="g-card" style="margin-left:15px;">
                <div class="title">
                    最新消息
                    <router-link to="/" class="more" @click="showMsgModel">更多 ></router-link>
                </div>
                <div class="g-msgs">
                    <div class="msg" v-for="item in userMessages" :key="item">
                        <div class="msg-icon"></div>
                        <div class="msg-text">{{ item.title }}</div>
                        <span>{{ item.createTime }}</span>
                    </div>
                </div>
            </div>
            <!-- <div class="g-card" style="margin-left:15px;">
                <div class="title">最新检验风险</div>
                <Grid :gridDatas="grid02" v-on:getTeg="toDetail"></Grid>
            </div> -->
        </div>

        <div class="cards">
            <div class="g-card" style="margin-right:15px;">
                <div class="title">最新漏洞</div>
                <Grid :gridDatas="grid03" v-on:getTeg="doTheThing($event, this)"></Grid>
            </div>
            <div class="g-card" style="margin-left:15px;">
                <div class="title">最新通报</div>
                <div class="data-table">
                    <a-table :columns="columns" :pagination="false" :row-key="(record) => record.id" :data-source="grid05" :loading="loading">
                        <template #status="{record}">
                            <span class="span-circle UnReported" v-if="record.status === 'UnReported'"> 未通报</span>
                            <span class="span-circle Reported" v-else-if="record.status === 'Reported'">待签收</span>
                            <span class="span-circle Handled" v-else-if="record.status === 'Handled'">待反馈</span>
                            <span class="span-circle Uploaded" v-if="record.status === 'Uploaded'">待确认</span>
                            <span class="span-circle Confirmed" v-if="record.status === 'Confirmed'">已完成</span>
                        </template>
                        <template #action="{record}">
                            <router-link style="margin-right:5px;" :to="{ path: '/tongbao', query: { firmName: record.firmName } }"
                                ><img title="查看详情" src="@/assets/images/cz-select.png"
                            /></router-link>
                        </template>
                    </a-table>
                </div>
            </div>
        </div>
        <!-- 分局下属派出所 -->
        <div class="card" v-if="roleId == 1">
            <div class="title">辖区</div>
            <div class="list-cards">
                <div class="lcard" v-for="item in grid04" :key="item">
                    <div class="h">{{ item.name }}</div>
                    <div class="b">
                        单位总数 <span> {{ item.firmCount }}个</span>
                    </div>
                    <div class="b" style="background:#F4F4F4">
                        资产总数
                        <span>
                            <font style="color: #4687FF;">{{ item.assetCount }}</font> 个</span>
                    </div>
                    <div class="b">
                        漏洞总数
                        <span>
                            <font style="color: #FE4E50;">{{ item.bugCount }}</font> 个</span>
                    </div>
                    <div class="b">
                        通报总数
                        <span>
                            <font style="color: #FE4E50;">{{ item.reportCount }}</font> 个</span>
                    </div>
                </div>
            </div>
        </div>
        <!-- 消息列表框 -->
        <a-modal v-model:visible="isShowMsgLest" width="90%" title="最新消息列表">
            <template #footer>
                <a-button key="back" @click="close">关闭</a-button>
            </template>
            <div class="card" style="min-height:300px">
                <Grid :gridDatas="msgs"></Grid>
            </div>
        </a-modal>
    </div>
</template>

<script>
import Grid from "@/components/gridBody";
import httpRequest from "@/util/httpRequest";
export default {
    name: "disktop",
    components: {
        Grid,
    },
    data() {
        return {
            userMessages: [],
            roleId: null, //1：分局，2.派出所
            bugCount: 0,
            assetCount: 0,
            firmCount: 0,
            inspectCount: 0,
            reportCount: 0,
            grid01: {
                title: "",
                data: [],
                pageData: false,
                columns: [
                    {
                        title: "单位名称",
                        dataIndex: "name",
                        key: "name",
                    },
                    {
                        title: "风险等级",
                        dataIndex: "severity",
                        key: "severity",
                        slots: {
                            customRender: "severity",
                        },
                    },
                    {
                        title: "高危漏洞",
                        dataIndex: "highBugCount",
                        key: "highBugCount",
                    },
                    {
                        title: "中危漏洞",
                        dataIndex: "mediumBugCount",
                        key: "mediumBugCount",
                    },
                    {
                        title: "低危漏洞",
                        dataIndex: "lowBugCount",
                        key: "lowBugCount",
                    },
                    {
                        title: "操作",
                        key: "action",
                        slots: {
                            customRender: "action",
                        },
                    },
                ],
            },
            grid02: {
                title: "",
                data: [],
                pageData: false,
                columns: [
                    {
                        title: "单位名称",
                        dataIndex: "firmName",
                        key: "firmName",
                        slots: {
                            customRender: "inspectionFirmName",
                        },
                    },
                    {
                        title: "风险数",
                        dataIndex: "riskCount",
                        key: "agriskCounte",
                    },
                    {
                        title: "检验时间",
                        dataIndex: "inspectTime",
                        key: "inspectTime",
                         slots: {
                            customRender: "time",
                        },
                    },
                    {
                        title: "报告时间",
                        key: "createTime",
                        dataIndex: "createTime",
                         slots: {
                            customRender: "time",
                        },
                    },
                    // {
                    //     title: "操作",
                    //     key: "action",
                    //     slots: {
                    //         customRender: "action",
                    //     },
                    // },
                ],
            },
            grid03: {
                title: "",
                data: [],
                pageData: false,
                columns: [
                    {
                        title: "漏洞等级",
                        dataIndex: "severity",
                        key: "severity",
                        slots: {
                            customRender: "severity",
                        },
                    },
                    {
                        title: "漏洞名称",
                        dataIndex: "vulnName",
                        key: "vulnName",
                    },
                    {
                        title: "所属单位",
                        dataIndex: "firmName",
                        key: "firmName",
                    },
                    {
                        title: "发现时间",
                        key: "createTime",
                        dataIndex: "createTime",
                    },
                    {
                        title: "操作",
                        key: "action",
                        slots: {
                            customRender: "action",
                        },
                    },
                ],
            },
            grid04: [],
            grid05: [],
            isloading: false,
            columns: [
                {
                    title: "所属辖区",
                    dataIndex: "psName",
                    key: "psName",
                },
                {
                    title: "通报状态",
                    dataIndex: "status",
                    key: "status",
                    slots: { customRender: "status" },
                },
                {
                    title: "单位名称",
                    dataIndex: "firmName",
                    key: "firmName",
                },
                {
                    title: "操作时间",
                    dataIndex: "editTime",
                    key: "editTime",
                },
                {
                    title: "操作",
                    key: "status",
                    slots: { customRender: "action" },
                    align: "right",
                },
            ],
            msgs: {
                title: "",
                data: [],
                pageData: {
                    pageNo: 1,
                },
                columns: [
                    {
                        title: "消息内容",
                        dataIndex: "content",
                        key: "content",
                    },
                    {
                        title: "接收者",
                        dataIndex: "psName",
                        key: "psName",
                    },
                    {
                        title: "发送时间",
                        key: "createTime",
                        dataIndex: "createTime",
                    },
                ],
            },
            isShowMsgLest:false,
        };
    },
    mounted() {
        this.thisPostList();
        if (localStorage.getItem("roleId")) {
            this.roleId = JSON.parse(localStorage.getItem("roleId"));
        }
    },
    methods: {
        thisPostList() {
            httpRequest.post("首页", {}).then((res) => {
                this.bugCount = res.data.bugCount;
                this.assetCount = res.data.assetCount;
                this.firmCount = res.data.firmCount;
                this.inspectCount = res.data.inspectCount;
                this.reportCount = res.data.reportCount;
                this.userMessages = res.data.userMessages;
                this.grid01.data = res.data.riskRank;
                this.grid02.data = res.data.newInspectReports;
                this.grid03.data = res.data.newBugs;
                this.grid04 = res.data.policeStations;
                this.grid05 = res.data.newReports;
            });
        },
        toDetail(e){
            this.$router.push({ name: "ManagementDtl", params: { id: e.id } });
        },
        toTongbao(e){
            this.$router.push({ name: "tongbao", params: { firmName: e.firmName } });
        },
        doTheThing(e, that) {
            that.$router.push({ name: "bugMgmtDtl", query: { id: e.id } });
        },
        close() {
            this.isShowMsgLest = false;
        },
        showMsgModel() {
            this.isShowMsgLest = true;
            httpRequest.post("消息列表", this.msgs.pageData).then((res) => {
                this.msgs.data = res.data.list;
                this.msgs.pageData.current = this.msgs.pageData.pageNo = res.data.pageNo;
                this.msgs.pageData.total = res.data.pages * this.msgs.pageData.pageSize;
            });
        },
    },
};
</script>

<style lang="less" scoped>
.body {
    .logos-c {
        display: flex;
        justify-content: flex-start;
        .margin-box {
            max-width: 20px;
            flex: 1 0 auto;
        }
        .cpt {
            display: flex;
            width: calc((100% - 40px) / 4);
            height: 106px;
            background: #ffffff;
            border: 1px solid #e5e5e5;
            border-radius: 4px;
            margin-right: 0px;
            overflow: hidden;
            padding: 12px 20px;
            .img-body {
                width: 80px;
                height: 80px;

                .img-c {
                    width: 80px;
                    height: 80px;
                    img {
                        display: block;
                        width: 100%;
                        height: 100%;
                    }
                }
            }
            .t {
                width: 100%;
                padding-left: 40px;
                text-align: left;
                h3 {
                    font-size: 36px;
                    font-weight: bold;
                    color: #333333;
                    line-height: 30px;
                    margin-bottom: 12px;
                    margin-top: 6px;
                }
                p {
                    font-size: 16px;
                    font-weight: 400;
                    color: #333333;
                    margin-bottom: 0;
                }
            }
        }
    }
    .cards {
        display: flex;
        margin-top: 30px;
        .g-card {
            width: calc(50% - 15px);
            padding: 16px;
            background: #ffffff;
            box-shadow: 0px 4px 8px 0px rgba(25, 36, 59, 0.11);
            border-radius: 8px;
            .more {
                font-size: 14px;
                font-weight: 400;
                color: #a7a7a7;
            }
            .g-msgs {
                text-align: left;
                font-size: 15px;
                font-weight: 400;
                color: #a7a7a7;
                width:100%;
                .msg {
                    width: 100%;
                    position: relative;
                    padding-right: 120px;
                    padding-left: 20px;
                    height: 24px;
                    line-height: 24px;
                    color: #999;
                    .msg-icon {
                        margin: 8px 6px;
                        width: 8px;
                        height: 8px;
                        background: #ee7f44;
                        border-radius: 50%;
                        position: absolute;
                        left: 0;
                        top: 0;
                    }
                    .msg-text {
                        width: 370px;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap;
                        font-size: 14px;
                        width: 100%;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap;
                    }
                    span {
                        font-size: 12px;
                        position: absolute;
                        right: 0;
                        top: 0;
                    }
                }
            }
        }
        .title {
            margin: 0 0 20px 0;
            text-align: left;
            border-left: 2px solid #4687ff;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-left: 10px;
            text-align: left;
            font-size: 20px;
            font-weight: bold;
            color: #333333;
        }
    }
    .card {
        margin-top: 30px;
        padding: 16px;
        background: #ffffff;
        box-shadow: 0px 4px 8px 0px rgba(25, 36, 59, 0.11);
        border-radius: 8px;
        .title {
            margin: 0 0 20px 0;
            text-align: left;
            border-left: 2px solid #4687ff;
            display: flex;
            justify-content: left;
            align-items: flex-end;
            padding-left: 10px;
            text-align: left;
            font-size: 20px;
            font-weight: bold;
            color: #333333;
        }
    }
    .list-cards {
        text-align: left;
        display: flex;
        flex-wrap: wrap;
        .lcard {
            width: calc((100% - 80px) / 5);
            margin: 10px 20px 10px 0;
            background: #ffffff;
            box-shadow: 0px 4px 8px 0px rgba(25, 36, 59, 0.11);
            border: 1px solid #dfdfdf;
            .h {
                padding: 10px 20px;
                width: 100%;
                height: 42px;
                background: #f4f4f4;
                font-size: 16px;
                font-weight: 600;
            }
            .b {
                padding: 5px 20px;
                width: 100%;
                font-size: 16px;
                font-weight: 400;
                color: #666666;
                span {
                    float: right;
                }
            }
            &:last-child{
                margin-right: 0px;
            }
        }
    }
}
</style>
